<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../layui/css/layui.css" media="all">
<title>药品增加</title>
</head>

<body>

	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>药品增加列表</legend>
	</fieldset>

	<form class="layui-form" action="../../../DrugModel/add.action"
		method="post" id="myform">
		<input type="hidden" id="drugId" name="drugId">
		<div class="layui-form-item">
			<label class="layui-form-label">药品名称</label>
			<div class="layui-input-block">
				<input type="text" name="drugName" id="drugName"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input" maxlength="9">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">药品类型</label>
			<div class="layui-input-block">
				<select name="dtId" id="dtId"
					autocomplete="off" class="layui-input">
					<option></option>
				</select>
			</div>
		</div>
		<!-- <div class="layui-form-item">
	        <label class="layui-form-label">药品类型</label>
	        <div class="layui-input-inline">
	            <div class="layui-unselect layui-form-select downpanel">
	                <div class="layui-select-title">
	                    <span class="layui-input layui-unselect" id="treeclass">选择类型</span>
	                    <input type="hidden" name="dtID" id = "id" value="0">
	                    <i class="layui-edge"></i>
	                </div>
	                <dl class="layui-anim layui-anim-upbit">
	                    <dd>
	                        <ul id="classtree"></ul>
	                    </dd>
	                </dl>
	            </div>
	        </div>
	    </div> -->
		<div class="layui-form-item">
			<label class="layui-form-label">药品价格</label>
			<div class="layui-input-block">
				<input onblur="price()"  type="number" name="drugPrice" id="drugPrice"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">建议零售</label>
			<div class="layui-input-block">
				<input onblur="prices()"  type="number" name="drugPrices" id="drugPrices"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">药品单位</label>
			<div class="layui-input-block">
				<input type="text" name="pov" id="pov"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input" maxlength="10">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">拼音简称</label>
			<div class="layui-input-block">
				<input type="text" name="drugPinyin" id="drugPinyin"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input" maxlength="20">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<div class="layui-upload">
					<label class="layui-form-label">药品图片</label>
					<button type="button" class="layui-btn" id="test1">药品图片</button>
					<div class="layui-upload-list" style="margin:10px 54%;">
						<img class="layui-upload-img" id="demo1" width="90px" height="90px">
						<p id="demoText" style="width:120px;margin:10px 0px;"></p>
						<input type="hidden" id="drugImg" name="drugImg">
					</div>
				</div>
			</div>
		</div>
		<!-- 提交重置 -->
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input  type="submit" class="layui-btn" lay-submit=""
				lay-filter="drugAdd" value="立即提交">
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>

	<script src="../../../layui/layui.js"></script>
	<script type="text/javascript" src="../../../res/wzw/js/jquery.min.1.6.4.js"></script>
	<script src="../../../res/wzw/js/jquery-1.10.2.js"></script>

	<script>
	//表单验证
	/*var num=0;
	function check(){
		var drugName = document.getElementById("drugName").value;
		//var url = "../../../DrugModel/findSpecification.action";
		 $.ajax({
            url:"../../../DrugModel/findSpecification.action",
            type:"post",
            data:{drugName:drugName},
            async: false,
            success:function(data){
            	if(data.num<1){
    				layer.msg('请添加说明书', {
						  icon: 1,
						  time: 2000 //1秒关闭（如果不配置，默认是3秒）
						}, function(){
					});
    				num=data.num;
    			}
            	if(data.num>=1){
            		layer.msg('添加成功', {
						  icon: 1,
						  time: 2000 //1秒关闭（如果不配置，默认是3秒）
						}, function(){
							parent.location.reload();
					});
            		num=data.num;
            	}
            },
            error:function(e){
                alert("错误！！");
                window.clearInterval(timer);
            }
        });
		if(num==0){
			return false;
		}
		if(num>0){
			return true;
		}
	} */
	
	
	function price(){
	    var price = document.getElementById('drugPrice').value;
	    var a=price.split(".")
	    if(price<=0||price>=1000){
	       $("#drugPrice").attr("placeholder","价格范围1-999￥");
	       document.getElementById('drugPrice').value="";
	       return false;
	    }else{
	   		var num = new Number(a[0]);
	   		document.getElementById('drugPrice').value=""+num.toFixed(2)+""
	    }
	}
	function prices(){
	    var price = document.getElementById('drugPrices').value;
	    var a=price.split(".")
	    if(price<=0||price>=1000){
	       $("#drugPrices").attr("placeholder","价格范围1-999￥");
	       document.getElementById('drugPrices').value="";
	       return false;
	    }else{
	   		var num = new Number(a[0]);
	   		document.getElementById('drugPrices').value=""+num.toFixed(2)+""
	    }
	}
	layui.use(['form', 'layer','upload'], function(){
	  var form = layui.form
	  ,upload= layui.upload
	  ,layer = layui.layer
	  ,$ = layui.$;
	  
	  form.on('submit(drugAdd)',function(){
			parent.location.reload(); // 父页面刷新
	  });
	  
	  var url = "../../../DrugModel/findAllType.action";
		$.post(url,null,function(data){
			for(var i=0;i<data.length;i++){
				$("#dtId").append("<option value="+data[i].dtId+">"+data[i].dtName+"</option>");
			}
			//form表单重新渲染
			form.render();
		},dataType="JSON");
		
		form.render('select','selFilter'); 
		
		//普通图片上传
		 upload.render({
		    elem: '#test1'
		    ,url: '../../../upload/uploadFile'
		    ,before: function(obj){
		      //预读本地文件示例，不支持ie8
		      obj.preview(function(index, file, result){
		        $('#demo1').attr('src', result); //图片链接（base64）
		      });
		    }
		    ,done: function(res){
		      //如果上传失败
		      if(res.code > 0){
		        return layer.msg('上传失败');
		      }
		      //上传成功
		      $("#drugImg").val(res.url);
		    }
		    ,error: function(){
		      //演示失败状态，并实现重传
		      var demoText = $('#demoText');
		      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
		      demoText.find('.demo-reload').on('click', function(){
		        uploadInst.upload();
		      });
		    }
		  });
	});
</script>

</body>
</html>